<?php
	namespace Admin\Controller;

	class OrderController extends CommonController{
		public function index(){
			$ordermodel=M('Order_list');
			$total=$ordermodel->count();
			$page=new \Think\Page($total,5);
			$page->setConfig('prev','上一页');
			$page->setConfig('next','下一页');
			$page_str=$page->show();
			$limit=$page->firstRow.','.$page->listRows;
			$list=$ordermodel->field('ol.uid,u.name,u.id uid,ol.ordernumber olo,ol.is_fu,ol.is_show,add.address,ol.add_id,ol.id')->table('user u,order_list ol,`address` `add`')->where("u.id=ol.uid and ol.`add_id`=`add`.id ")->limit($limit)->select();

			$this->assign('Page',$page_str);
			$this->assign('list',$list);
			$this->display();
		}
		public function is_show(){
			$id=$_GET['id'];
			$ordermodel=M('Order_list');
			$list=$ordermodel->where("id=".$id)->find();
			if($list['is_fu']==0){
				$this->error('未付款');
				return false;
			}
			$data['is_show']=1;
			$res=$ordermodel->where("id=".$id)->save($data);
			if($res){
				$this->success('发货成功',U('Order/index'),2);
			}else{
				$this->error('发货失败');
			}
		}
		public function del(){
			$id=$_GET['id'];
			$listmodel=M('Order_list');
			$list=$listmodel->where("id=".$id)->find();
			if($list['is_fu']==1){
				if($list['is_show']!=2){
				$this->error('未确认收货不能删除');
				}
			}
			$listmodel->startTrans();
			$res=$listmodel->where("id=".$id)->delete();
			if($res){
				$infomodel=M('Order_info');
				$resu=$infomodel->where("order_id=".$id)->delete();
				if($resu){
					$listmodel->commit();
					$this->error('删除成功',U('Order/index'),1);
				}else{
					$listmodel->rollback();
					$this->error('删除失败');
				}
			}
		}
	}